package com.example.demo.controller;
import com.example.demo.model.Cd;
import com.example.demo.service.ICdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator 张喜英
 */

    @Api(tags = "cd")
    @RestController
    @RequestMapping("/swagger5")
    public class CdController {
        @Autowired
        private ICdService cdService;
    @CrossOrigin
    @ApiOperation(value="对菜单信息的添加方法")
    @PostMapping("/insertcd")
    public int insertCd(@RequestBody Cd cd){
        System.out.println("进入添加菜单接口" );
        return cdService.insertCd(cd);
    }

    @PostMapping("/getAll")
    public List<Cd> getAllCd(@RequestBody Cd cd)
    {
        System.out.println("进入查询方法");
        List<Cd> listCd=cdService.getAllCd(cd);
        return listCd;
    }
    @PostMapping("/editCd")
    public int EditCd(@RequestBody Cd cd){
        System.out.println("添加修改方法");
        return cdService.updateCd(cd);
}
    @GetMapping("/delCd")
    public int Delete(int cdid){
        System.out.println("进入删除方法");
        int returnValues=0;
        if(cdid!=0){
            Cd cd=new Cd();
            cd.setCdid(cdid);
        returnValues=cdService.deleteCd(cd);
        }
        return returnValues;
    }

    @GetMapping("/getOne")
    public Cd getCd(int cdid){
        Cd cd=new Cd();
        System.out.println("进入单条查询方法");
        if(cdid!=0){
            Cd cd1=new Cd();
            cd1.setCdid(cdid);
            cd=cdService.getCd(cd1);
            System.out.println("返回的数据集合为:"+cd.getCdid());
        }
        return cd;
    }








}
